﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    mc:Ignorable="d"
                    xmlns:mr="http://mishrareader.codeplex.com/Reader"
                    xmlns:Entities="clr-namespace:MishraReader.Entities;assembly=MishraReader.Entities"
                    xmlns:interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                    xmlns:viewModels="clr-namespace:MishraReader.ViewModels;assembly=MishraReader.ViewModels"
                    xmlns:mishraReader="clr-namespace:MishraReader;assembly=MishraReader.ViewModels">

    <DataTemplate DataType="{x:Type viewModels:MishraReaderViewModel}">
        <DataTemplate.Resources>           
            
            <Style x:Key="PopButtonStyle" TargetType="{x:Type Button}">
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Border x:Name="border" Background="Transparent" Tag="{TemplateBinding Tag}" RenderTransformOrigin="0.5,0.5">
                                <Border.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform/>
                                        <SkewTransform/>
                                        <RotateTransform/>
                                        <TranslateTransform Y="5"/>
                                    </TransformGroup>
                                </Border.RenderTransform>
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition GeneratedDuration="0:0:0.15">
                                                <VisualTransition.GeneratedEasingFunction>
                                                    <ExponentialEase EasingMode="EaseOut" Exponent="4"/>
                                                </VisualTransition.GeneratedEasingFunction>
                                            </VisualTransition>
                                        </VisualStateGroup.Transitions>
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="MouseOver">
                                            <Storyboard>
                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="content">
                                                    <EasingDoubleKeyFrame KeyTime="0" Value="0.8"/>
                                                </DoubleAnimationUsingKeyFrames>
                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="border">
                                                    <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                                                </DoubleAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Pressed">
                                            <Storyboard>
                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="content">
                                                    <EasingDoubleKeyFrame KeyTime="0" Value="0.6"/>
                                                </DoubleAnimationUsingKeyFrames>
                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="border">
                                                    <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                                                </DoubleAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Disabled">
                                            <Storyboard>
                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="content">
                                                    <EasingDoubleKeyFrame KeyTime="0" Value="0.2"/>
                                                </DoubleAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <ContentPresenter x:Name="content" Opacity="1" Tag="{TemplateBinding Tag}"/>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </DataTemplate.Resources>

        <Grid Margin="0" FocusManager.FocusedElement="{Binding ElementName=itemsList}" d:DesignWidth="866" d:DesignHeight="512">
            <Grid.InputBindings>
                <KeyBinding Key="N" Command="{Binding SelectNextItemCommand}" />
                <KeyBinding Key="P" Command="{Binding SelectPreviousItemCommand}" />
            </Grid.InputBindings>
            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="100" Width="{Binding Options.LeftColumnWidth, Mode=TwoWay}" />
                <ColumnDefinition MinWidth="100" Width="{Binding Options.MiddleColumnWidth, Mode=TwoWay}"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="50" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <!-- Background of the first column -->
            <Rectangle Margin="0" Grid.RowSpan="2" Fill="WhiteSmoke" IsHitTestVisible="False"/>
            
            <!-- Background of the middle item column -->
            <Rectangle Margin="0" Grid.Column="1" Grid.RowSpan="2" Fill="White"  IsHitTestVisible="False"/>
            
            <!-- Shows progress at the top  -->
            <ProgressBar Height="3" 
                     IsIndeterminate="True" 
                     Visibility="{Binding IsSync, Converter={StaticResource BoolToVisibilityConverter}}"  
                     VerticalAlignment="Top" 
                     IsHitTestVisible="False" />
            
            <!-- Area at the top with the logo, username and settings -->
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Height="30" VerticalAlignment="Top" Margin="9,9,0,0">
                <Border Background="{DynamicResource MetroAccentBrush}" Width="22" Height="22" Margin="0" VerticalAlignment="Top" HorizontalAlignment="Left">
                    <Image Source="/MishraReader;component/Assets/MishraReaderSmall.png" UseLayoutRounding="True"  />
                </Border>
                <StackPanel 
                Margin="9,0,0,0" RenderTransformOrigin="0.5,0.5" 
                VerticalAlignment="Top"
                TextOptions.TextFormattingMode="Display">
                    <StackPanel.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform Y="-3"/>
                        </TransformGroup>
                    </StackPanel.RenderTransform>
                    <TextBlock 
                    Text="{Binding UserName, FallbackValue=username}" 
                    HorizontalAlignment="Left" 
                    Style="{StaticResource MetroSmallBoldText}" 
                    Foreground="{DynamicResource MetroAccentBrush}" 
                    />
                    <Button 
                    Content="{x:Static mishraReader:Strings.Settings}"  
                    Command="{Binding ViewSettingsCommand}" 
                    HorizontalAlignment="Left" 
                    Style="{DynamicResource MetroPathButton}" 
                    FontSize="{DynamicResource TinyTextSize}" 
                    FontFamily="{DynamicResource SemiBoldFont}" 
                    Foreground="{DynamicResource MetroTextLight}" 
                    Margin="0,-2,0,0"/>
                </StackPanel>
            </StackPanel>
            
            <!-- This grid contains the categories and feed list -->
            <Grid Grid.Column="0" Grid.Row="1" Margin="9,0,12,20">
                <TreeView ItemsSource="{Binding Categories}" 
                         Style="{DynamicResource FeedTreeView}"
                         TextOptions.TextFormattingMode="Display" 
                          ItemContainerStyle="{DynamicResource CategoriesTreeViewItemStyle}"
                          ScrollViewer.HorizontalScrollBarVisibility ="Auto"
                         >
                    <TreeView.Resources>
                        <HierarchicalDataTemplate DataType="{x:Type Entities:SubscriptionCategory}"
                                                  ItemsSource="{Binding Subscriptions}"
                                                  ItemContainerStyle="{StaticResource FeedsTreeViewItemStyle}">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Label}" />
                                <TextBlock Text="{Binding UnreadCount, StringFormat=' (\{0\})'}"
                                           VerticalAlignment="Center"
                                            Opacity="0.8" 
                                            Margin="0,0,0,-3"
                                            TextElement.FontSize="{StaticResource NormalTextSize}" 
                                            Visibility="{Binding HasUnreads, Converter={StaticResource BoolToVisibilityConverter}}"
                                            />
                            </StackPanel>
                        </HierarchicalDataTemplate>
                        <DataTemplate DataType="{x:Type Entities:Subscription}">
                            <StackPanel Orientation="Horizontal" x:Name="label">
                                
                            <TextBlock Text="{Binding Title}" VerticalAlignment="Center" />
                                <TextBlock Text="{Binding UnreadsCount, StringFormat=' (\{0\})'}"
                                           VerticalAlignment="Center"
                                            Opacity="0.8" 
                                            Margin="0,0,0,0"
                                            Visibility="{Binding HasUnreads, Converter={StaticResource BoolToVisibilityConverter}}"
                                            />
                            </StackPanel>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding HasUnreads}" Value="True">
                                    <Setter TargetName="label" Property="TextBlock.FontWeight" Value="Bold" />
                                    
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </TreeView.Resources>
                    <interactivity:Interaction.Behaviors>
                        <mr:BindableTreeViewSelectedItemBehavior Binding="{Binding SelectedCategory, Mode=TwoWay}"/>
                    </interactivity:Interaction.Behaviors>
                </TreeView>
            </Grid>

            <Button Grid.Column="0" Focusable="False" Style="{StaticResource MetroCleanButton}" Command="{Binding LoadNewItemsCommand}" Height="25" 
                    x:Name="panAutoRefreshMessage"  VerticalAlignment="Top" HorizontalAlignment="Center" >
                <Button.RenderTransform>
                    <TranslateTransform Y="-30" />
                </Button.RenderTransform>
                <Border Background="{StaticResource MetroAccentBrush}">
                    <TextBlock Margin="30,6,30,4" Text="{Binding NewItemsMessage}" 
                               Style="{StaticResource MetroSmallText}"  
                               Foreground="{StaticResource MetroFeatureContrastBrush}" />

                </Border>
            </Button>


            <GridSplitter Grid.Column="0" Grid.RowSpan="2" Width="3" Background="WhiteSmoke" HorizontalAlignment="Right" VerticalAlignment="Stretch" />
            
         
            <!-- Grid that contains the mark all read and items list  -->
            <Grid Grid.Column="1" Grid.Row="1"  Margin="10,0,20,20">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                
                <mr:AnimatedListBox Grid.Row="0" Grid.ColumnSpan="2" HorizontalAlignment="Left" Margin="0,0,0,10" 
                                  VerticalAlignment="Center" 
                                  ItemsSource="{Binding Headers}"
                                  SelectedItem="{Binding SelectedHeader, Mode=TwoWay}"   
                                  IsSynchronizedWithCurrentItem="True"
                                  Style="{DynamicResource HorizontalMenuListBox}" >
                    <mr:AnimatedListBox.ItemTemplate>
                        <DataTemplate DataType="{x:Type mishraReader:MenuHeader}">
                            <Grid  >
                                <TextBlock Text="{Binding Label}"  />
                                <TextBlock
                            Text="{Binding Count}" 
                            Margin="{Binding ActualWidth, Converter={StaticResource ActualWidthToNegativeMarginConverter}, RelativeSource={RelativeSource Self}}" 
                            HorizontalAlignment="Right" 
                            FontSize="{DynamicResource SmallTextSize}" 
                            FontFamily="{StaticResource DefaultFont}" 
                            TextOptions.TextFormattingMode="Display"
                            VerticalAlignment="Top"   
                            Visibility="{Binding IsCountVisible, Converter={StaticResource BoolToVisibilityConverter}}" />
                            </Grid>
                        </DataTemplate>
                    </mr:AnimatedListBox.ItemTemplate>
                </mr:AnimatedListBox>

                <Grid Grid.Row="1" Margin="0,0,0,0" VerticalAlignment="Top" ClipToBounds="True"  Height="30">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <StackPanel Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal" Margin="0,0,0,5" >

                        <mr:ComboButton IsDropDownOpen="{Binding IsMoreOptionsOpen, Mode=TwoWay}"  
                                              Style="{DynamicResource ComboButtonCircleStyle}" 
                                              ArrowMargin="0,0,0,-1"
                                              ArrowHorizontalAlignment="Center"
                                              Margin="0,0,10,0" 
                                              VerticalOffset="0"
                                              HorizontalOffset="-55"
                                              ToolTip="{x:Static mishraReader:Strings.MarkAllAsRead}"
                                              Visibility="{Binding CanMarkAllAsRead, Converter={StaticResource BooleanToHiddenVisibilityConverter}}">
                            <mr:ComboButton.Header>
                                <Path Data="{StaticResource PathCheckmark}" x:Name="readStatus" Width="14" Height="14" Fill="{DynamicResource MetroLine}" Stretch="Fill" />
                            </mr:ComboButton.Header>
                            <mr:ComboButton.Content>
                                <Button Content="{x:Static mishraReader:Strings.MarkAllAsRead}" Command="{Binding MarkAllAsReadCommand}" />
                            </mr:ComboButton.Content>
                        </mr:ComboButton>
                        
                        <!--<Button Style="{DynamicResource MetroCircleButton}" Visibility="{Binding CanMarkAllAsRead, Converter={StaticResource BooleanToHiddenVisibilityConverter}}" Command="{Binding MarkAllAsReadCommand}" RenderTransformOrigin="0.5,0.5" >
                            <Path Data="{StaticResource PathCheckmark}" x:Name="readStatus" Width="14" Height="14" Fill="{DynamicResource MetroLine}" Stretch="Fill" />
                        </Button>-->

                        <Button Style="{DynamicResource MetroCircleButton}"  Command="{Binding RefreshCommand}" ToolTip="Refresh" RenderTransformOrigin="0.5,0.5" >
                            <Image Source="/MishraReader;component/Assets/Light/Refresh.png" Stretch="None" Margin="0" Width="24" />
                        </Button>

                    </StackPanel>
                    
                    <Rectangle Fill="{DynamicResource MetroScollbarBg}" Margin="0" Height="1" VerticalAlignment="Bottom" Grid.ColumnSpan="2"/>

                </Grid>

                <Grid Grid.Row="2" Margin="0,10,0,0">

                    <mr:FeedItemsListBox x:Name="itemsList" 
                                           RequireMoreDataCommand="{Binding RequireMoreDataCommand}"  
                                           ItemsSource="{Binding ItemsView.UnderlyingSource.View}" 
                                           SelectedItem="{Binding CurrentItem, Mode=TwoWay}">
                        <mr:FeedItemsListBox.Resources>
                            <mr:CommandReference x:Key="toggleReadCommand" Command="{Binding ToggleReadCommand}" />
                        </mr:FeedItemsListBox.Resources>

                        <mr:FeedItemsListBox.ItemContainerStyle>
                            <Style TargetType="{x:Type ListBoxItem}">
                                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                            <Grid Background="Transparent" Margin="0,0,0,5" x:Name="Grid">
                                                <Rectangle x:Name="OverElement"  Fill="{DynamicResource MetroAccentBrush}" Opacity="0" />
                                                <Rectangle x:Name="SelectedElement" Margin="1" Opacity="0" Width="15" HorizontalAlignment="Left" RadiusX="1" RadiusY="1" Fill="{DynamicResource MetroAccentBrush}" />
                                                <ContentPresenter Margin="0,0,0,0" />
                                            </Grid>
                                            <ControlTemplate.Triggers>

                                                <Trigger Property="IsMouseOver" Value="True">
                                                    <Setter Property="Opacity" Value="0.1" TargetName="SelectedElement" />
                                                    <Setter Property="Opacity" Value="0.1" TargetName="OverElement" />
                                                </Trigger>

                                                <Trigger Property="IsSelected" Value="True">
                                                    <Setter Property="Opacity" Value="0.3" TargetName="SelectedElement" />
                                                    <Setter Property="Opacity" Value="0.2" TargetName="OverElement" />
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </mr:FeedItemsListBox.ItemContainerStyle>

                        <interactivity:Interaction.Behaviors>
                            <mr:ScrollIntoViewBehavior />
                        </interactivity:Interaction.Behaviors>
                    </mr:FeedItemsListBox>


                    <TextBlock 
                    TextOptions.TextFormattingMode="Display"
                    IsHitTestVisible="False" Text="{Binding EmptyText}" 
                    Visibility="{Binding HasItems, ConverterParameter=1, Converter={StaticResource BoolToVisibilityConverter}}" 
                    Foreground="{DynamicResource MetroTextLight}" 
                    Style="{DynamicResource MetroSmallText}" 
                    TextWrapping="Wrap" 
                    HorizontalAlignment="Center" 
                    VerticalAlignment="Center" />


                </Grid>

            </Grid>
            
            <GridSplitter Grid.Column="1" Grid.RowSpan="2" Width="3" Background="White" HorizontalAlignment="Right" VerticalAlignment="Stretch" />
            
            <!-- This is the gradient between the item list and the main content -->
            <Grid Grid.Column="2" HorizontalAlignment="Left" Grid.RowSpan="2" Width="20" IsHitTestVisible="False">
                <Rectangle Margin="0">
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
                            <GradientStop Color="#1F000000" Offset="0.448"/>
                            <GradientStop Color="#4A000000" Offset="0.125"/>
                            <GradientStop Color="#86000000"/>
                            <GradientStop Offset="1"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <Rectangle Width="1" HorizontalAlignment="Left" Fill="White" Margin="-1,0,0,0"/>
            </Grid>
            
            <!-- Main Content Area -->
            <Grid Grid.Column="2"  Margin="40,0,40,20" x:Name="contentPart" Grid.Row="1">
                <Grid Margin="0" VerticalAlignment="Center" HorizontalAlignment="Center" Opacity="0.5">
                    <Rectangle Fill="{DynamicResource MetroAccentBrush}" Width="100" Height="100" />
                    <Image Source="/MishraReader;component/Assets/MishraReader.png" Stretch="None" Margin="-5,0,0,0" />
                </Grid>
                <ContentPresenter Content="{Binding ItemViewModel}" />
            </Grid>

           
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding HasNewItems}" Value="True">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="panAutoRefreshMessage" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" >
                                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
                <DataTrigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="panAutoRefreshMessage" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" >
                                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-30" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.ExitActions>
            </DataTrigger> 
        </DataTemplate.Triggers>
        
    </DataTemplate>
    
    
</ResourceDictionary>